function deleteAllListOptions(listCtrl) {
    if (typeof listCtrl != 'undefined') {
        for (var j = listCtrl.options.length; j >= 0; j--) {
            listCtrl.options[j] = null;
        }
    }
}
function addOptionToList(listCtrl, aName, aValue) {
    addOption(listCtrl, aName, aValue, listCtrl.options.length);
}

function AddNewShippingAddress(addElement) {
    //Restricting the user from entering more than one new shipping address
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    for (var i = 0; i < document.salesOrderForm.shippingAddressId.length; i++) {
        if (document.salesOrderForm.shippingAddressId[i].value == -1) {
            pa.innerHTML = "Can not add more than one new Shipping Address";
            return;
        }
    }
    shipElement = addElement.name;
    if (document.salesOrderForm.endUser.value == "") {
        if (document.salesOrderForm.isEndCustomerShipAddress.checked && Number(document.salesOrderForm.odmId.value) > 0) {
            customerId = document.salesOrderForm.odmId.value;
        }
        else {
            customerId = document.salesOrderForm.customerId.value;
        }
        newWindow = window.open('addAddress.do?action=AddShippingAddress&customerId=' + customerId, 'shippingAddressPopup', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=400,height=400,left=550,top=180,resizable=no');
        newWindow.focus();
    }
    else {
        newWindow = window.open('addEndUserAddress.do?action=AddEndUserShippingAddress&endUserId=' + document.salesOrderForm.endUserId.value, 'shippingAddressPopup', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=400,height=400,left=550,top=180,resizable=no');
        newWindow.focus();
    }
}

function assignShippingAddress(elementName) {
    enableCustPartNos();
    enablePrices();

    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;

    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;

    document.salesOrderForm.action.value = "loadShippingAddress";
    document.salesOrderForm.submit();
}
function assignBillingAddress(elementName) {
    enableCustPartNos();
    enablePrices();

    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;

    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;

    document.salesOrderForm.action.value = "loadBillingAddress";
    document.salesOrderForm.submit();
}
function setReadOnlyForFreightInsructions(elementName)
{
    if (elementName.value == "-1")
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = true;
        document.salesOrderForm.freightInstructions.value = "";
    }
    if (elementName.value == "-2")
    {
        freightInstructionLabel.innerText = "New Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = false;
    }
    else if (Number(elementName.value) > 0)
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = true;
    }
}
function assignFreightInstructions(elementName)
{
    if (elementName.value == "-1")
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = true;
        document.salesOrderForm.freightInstructions.value = "";
    }
    else if (elementName.value == "-2")
    {
        freightInstructionLabel.innerText = "New Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = false;
        document.salesOrderForm.freightInstructions.value = "";
        document.salesOrderForm.freightInstructions.focus();
    }
    else if (Number(elementName.value) > 0)
        {
            enableCustPartNos();
            enablePrices();

            document.salesOrderForm.shippingAddress.disabled = false;
            document.salesOrderForm.billingAddress.disabled = false;

            document.salesOrderForm.salesTaxType.disabled = false;
            document.salesOrderForm.miscAsDouble.disabled = false;
            document.salesOrderForm.frieghtAsDouble.disabled = false;

            document.salesOrderForm.action.value = "loadFreightInstructions";
            document.salesOrderForm.submit();
        }
}
function getCustomerShippingAddress()
{
    var isEndCustomerShipAddress = document.salesOrderForm["isEndCustomerShipAddress"];
    isEndCustomerShipAddress.checked = false;

    enableFormFields();

    document.salesOrderForm.action.value = "loadEndCustomerDefualtShippingAddress";
    document.salesOrderForm.submit();
}

function enableFormFields()
{
    enableCustPartNos();
    enablePrices();

    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;

    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;
}
//Function for adding a new option to the shippingAddressId select list
function addShippingAddressIdOption(optionContent, optionValue)
{
    document.salesOrderForm.shippingAddressId.add(new Option(optionContent, optionValue));
}

function addShippingAddressContactPerson(shipAddressWithoutContactPerson, strShippingAddress, contactPerson)
{
    document.salesOrderForm.shippingAddress.value = strShippingAddress;
    document.salesOrderForm.shippingAddressId.value = -1;
    document.salesOrderForm.shippingContactPerson.length = 0;
    document.salesOrderForm.shippingContactPerson.length = 2;
    document.salesOrderForm.shippingContactPerson.options[0].text = "--- Select ---";
    document.salesOrderForm.shippingContactPerson.options[0].value = "";
    document.salesOrderForm.shippingContactPerson.options[1].text = contactPerson;
    document.salesOrderForm.shippingContactPerson.options[1].value = contactPerson;
    document.salesOrderForm.shippingContactPerson.value = contactPerson;

    shipContactPerson.length = 2;
    shipAddress.length = 2;

    shipContactPerson[0] = '';
    shipAddress[0] = shipAddressWithoutContactPerson;

    shipContactPerson[1] = contactPerson;
    shipAddress[1] = strShippingAddress;

}
function AddShippingTerms()
{
    var shippinglabel = document.getElementById("newShippingTerms");
    var letterOfCreditNoObj = document.getElementById("letterOfCreditNo");
    var lcIssuingBankObj = document.getElementById("lcIssuingBank");

    if (document.salesOrderForm.shippingTerms.value == -2)
    {
        document.salesOrderForm.newShippingTerms.style.visibility = "visible";
        document.salesOrderForm.newShippingTerms.value = '';
        shippinglabel.innerHTML = "New Pay Terms : ";
    }
    else
    {
        document.salesOrderForm.newShippingTerms.style.visibility = "hidden";
        shippinglabel.innerHTML = "";
    }
}
function taxFocus()
{
    document.salesOrderForm.newSalesTax.focus();
}
function setZeroPrice(no, lineno)
{
    if (document.salesOrderForm.quantity.length != null)
    {
        var element = eval(document.salesOrderForm["zeroPrice" + lineno]);
        if (element.checked == true)
        {
            document.salesOrderForm.unitPriceAsDouble[no].value = "0.0";
        }
    }
    else
    {
        if (eval("document.salesOrderForm.zeroPrice" + lineno).checked == true)
        {
            document.salesOrderForm.unitPriceAsDouble.value = "0.0";
        }
    }
}

function assignShippingAccount(elementName)
{
    var len = elementName.length;

    for (var i = 0; i < len; i++) {
        if (elementName.options[i].selected) {
            document.salesOrderForm.shippingMethodName.value = elementName.options[i].innerText;
        }
    }

    //document.salesOrderForm.shippingAccount.value = elementName.value;
    if (document.salesOrderForm.shippingMethod.value != -1)
    {
        document.salesOrderForm.shippingAccount.value = elementName.value;
    }
    else
        if (document.salesOrderForm.shippingMethod.value == -1)
        {
            document.salesOrderForm.shippingAccount.value = '';
            document.salesOrderForm.shippingMethodName.value = '';
        }

}

function dateValidation()
{
    var dateValue = "";
    var temp = document.salesOrderForm["requestDate"];

    if (temp.length == null)
    {
        if (chkDate(temp.value, "Requested Dock Date", "Y") == false)
        {
            errors = errMsg;
            temp.select();
            temp.focus();
        }
        else
        {
            return false;
        }

    }
    else {
        var partNo = document.salesOrderForm["manufacturingPartNo"];
        var i;
        for (i = 0; i < temp.length; i++)
        {
            if (partNo[i].value != '')
            {
                if (chkDate(temp[i].value, "Requested Dock Date ", "Y") == false)
                {
                    errors = errMsg;
                    temp[i].select();
                    temp[i].focus();
                    break;
                }
            }//if
        }//for

    } //else

    if (errors != '')
        return false;
    else
        return true;
}

function validateRequestDate(temp)
{
    errors = "";
    validateDate(temp.value);
    var pa = document.getElementById("errors");
    pa.innerHTML = errors;

    return;
}
function enableCustPartNos()
{
    var custPNo = eval('document.salesOrderForm.customerPartNo');
    if (custPNo.length == null)
    {
        custPNo.disabled = false;
    }
    else
    {
        for (var xx = 0; xx < custPNo.length; xx++)
        {
            custPNo[xx].disabled = false;
        }
    }
}
function enablePrices()
{
    if (isSample == 0)
    {
        var price = document.salesOrderForm["unitPriceAsDouble"];
        var zeroPrice = document.salesOrderForm["zeroPrice"];
        var expediteFee = document.salesOrderForm["expediteFee"];

        if (price.length == null)
        {
            var element1 = eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.jsLineItemNo.value));
            var element2 = eval("document.salesOrderForm.expediteFee" + (document.salesOrderForm.jsLineItemNo.value));
            price.disabled = false;
            element1.disabled = false;
            element2.disabled = false;
        }
        else
        {
            for (var i = 0; i < price.length; i++)
            {
                var element1 = eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.jsLineItemNo[i].value));
                var element2 = eval("document.salesOrderForm.expediteFee" + (document.salesOrderForm.jsLineItemNo[i].value));
                price[i].disabled = false;
                element1.disabled = false;
                element2.disabled = false;
            }
        }
    }
}

function enableLabelNumbers()
{
    var labelNo = eval('document.salesOrderForm.labelNumber');
    if (labelNo.length == null)
    {
        labelNo.disabled = false;
    }
    else
    {
        for (var xx = 0; xx < labelNo.length; xx++)
        {
            labelNo[xx].disabled = false;
        }
    }
}

function checkBaseOrderQty(selecteditem)
{
    var form = document.salesOrderForm;
    var mfPartNo;
    var size;
    size = keys.length;
    var lineitems = count;
    var qty;
    var i;
    var tempQty;
    var lQty;
    var gQty;
    var tempBaseOrderQty;
    var lineItemNo;
    var message = ''
    var paMessage = document.getElementById("message");

    if (lineitems > 2)
    {
        mfPartNo = form.manufacturingPartNo[selecteditem].value;
        mfPartNo = trim(mfPartNo.toLowerCase());
        qty = Number(trim(form.quantity[selecteditem].value));
        lineItemNo = form.jsLineItemNo[selecteditem].value;
    }
    else
    {
        mfPartNo = form.manufacturingPartNo.value;
        mfPartNo = trim(mfPartNo.toLowerCase());
        qty = Number(trim(form.quantity.value));
        lineItemNo = form.jsLineItemNo.value;
    }

    for (i = 0; i < size; i++)
    {
        if (mfPartNo == trim(keys[i].toLowerCase()) && baseOrderQty[i] != 'null' && baseOrderQty[i] != '')
        {
            if (isNaN(qty) || isNaN(baseOrderQty[i]))
            {
                return;
            }
            else
            {
                tempBaseOrderQty = Number(baseOrderQty[i]);

                if (tempBaseOrderQty != 0)
                {
                    if (qty > tempBaseOrderQty)
                    {
                        tempQty = qty % tempBaseOrderQty;
                        if (tempQty != 0)
                        {
                            for (j = qty; ; j++)
                            {
                                if (j % tempBaseOrderQty == 0)
                                {
                                    gQty = j;
                                    break;
                                }
                            }
                            for (j = qty; ; j--)
                            {
                                if (j % tempBaseOrderQty == 0)
                                {
                                    lQty = j;
                                    break;
                                }
                            }
                            message = message + '<br>' + "<li>Note: Line Item " + lineItemNo + " Quantity is not multiple of the Base Order Quantity (" + tempBaseOrderQty + ") of this Product. The nearest multiple quantities are " + lQty + " and " + gQty + ".";
                            //var pa=document.getElementById("errors");
                            paMessage.innerHTML = message;
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (qty < tempBaseOrderQty)
                    {
                        message = message + '<br>' + "<li>Note: Line Item " + lineItemNo + " Quantity is not multiple of the Base Order Quantity (" + tempBaseOrderQty + ") of this Product. The nearest multiple quantity is " + tempBaseOrderQty + ".";
                        paMessage.innerHTML = message;
                        return;
                    }
                }
                else
                {
                    message = '';
                    paMessage.innerHTML = message;
                    return;
                }
            }
        }
    }

}


function getComments(selecteditem)
{
    var form = document.salesOrderForm;
    var mfgPrtVal = form.manufacturingPartNo[selecteditem].value;

    var mfPartNo;
    var size;
    size = keys.length;
    var lineitems = count;

    if (lineitems > 2)
    {
        mfPartNo = form.manufacturingPartNo[selecteditem].value;
        mfPartNo = trim(mfPartNo.toLowerCase());

        for (i = 0; i < size; i++)
        {
            if (mfPartNo == trim(keys[i].toLowerCase()) && comments[i] != 'null')
            {
                form.lineItemDescription[selecteditem].value = comments[i];
                break;
            }
            else
            {
                form.lineItemDescription[selecteditem].value = "";
            }
        }
        for (i = 0; i < size; i++)
        {
            if (mfPartNo == trim(keys[i].toLowerCase()))
            {
                var custPartNosOptions = form.customerPartNo[selecteditem].options;
                var custPartNosOptionsLen = custPartNosOptions.length;
                for (var l = custPartNosOptionsLen - 1; l >= 0; l--)
                {
                    custPartNosOptions[l] = null;
                }
                custPartNosOptions[0] = new Option("Select Customer Part No", "");
                var tmpCustomerNos = customernos[i];
                for (var k = 0; k < tmpCustomerNos.length; k++)
                {
                    if (tmpCustomerNos[k] != '')
                    {
                        custPartNosOptions[k + 1] = new Option(tmpCustomerNos[k], tmpCustomerNos[k]);
                    }
                }
                custPartNosOptions[tmpCustomerNos.length + 1] = new Option("--Add New CustomerPart No--", "-2");
                break;
            }
        }
    }
    else
    {
        mfPartNo = form.manufacturingPartNo.value;
        mfPartNo = trim(mfPartNo.toLowerCase());

        for (j = 0; j < size; j++)
        {
            if (mfPartNo == trim(keys[j].toLowerCase()) && comments[j] != 'null')
            {
                form.lineItemDescription.value = comments[j];
                break;
            }
            else
            {
                form.lineItemDescription.value = "";
            }
        }//for
        for (i = 0; i < size; i++)
        {
            if (mfPartNo == trim(keys[i].toLowerCase()))
            {
                var custPartNosOptions = form.customerPartNo.options;
                var custPartNosOptionsLen = custPartNosOptions.length;
                for (var l = custPartNosOptionsLen - 1; l >= 0; l--)
                {
                    custPartNosOptions[l] = null;
                }
                custPartNosOptions[0] = new Option("Select Customer Part No", "");
                var tmpCustomerNos = customernos[i];
                for (var k = 0; k < tmpCustomerNos.length; k++)
                {
                    if (tmpCustomerNos[k] != '')
                    {
                        custPartNosOptions[k + 1] = new Option(tmpCustomerNos[k], tmpCustomerNos[k]);
                    }
                }
                custPartNosOptions[tmpCustomerNos.length + 1] = new Option("--Add New CustomerPart No--", "-2");
                break;
            }
        }
    }
    showHideNewCustPartNo(selecteditem);
}//fn
function selectContactPerson(element, idValue, indexValue)
{

    var yy = document.salesOrderForm.contactPerson.selectedIndex;

    if (element == 'CustomerContactPerson')
    {

        for (ss = 0; ss < customerContactPerson.length; ss++)
        {
            if (document.salesOrderForm.contactPerson.value == customerContactPerson[ss])
            {
                document.salesOrderForm.contactPerson.value = customerContactPerson[ss];
                document.salesOrderForm.phoneNumber.value = customerPhNo[ss];
                document.salesOrderForm.cellNumber.value = customerCellNo[ss];
                document.salesOrderForm.faxNumber.value = customerFax[ss];
                document.salesOrderForm.email.value = customerEmail[ss];

                document.salesOrderForm.phoneNumber.disabled = false;
                document.salesOrderForm.cellNumber.disabled = false;
                document.salesOrderForm.faxNumber.disabled = false;
                document.salesOrderForm.email.disabled = false;
                if (document.salesOrderForm.customerName.value == customerContactPerson[ss])
                {
                    document.salesOrderForm.cellNumber.disabled = true;
                }
            }
            else  if (document.salesOrderForm.contactPerson.value == '')
            {
                document.salesOrderForm.contactPerson.value = '';
                document.salesOrderForm.phoneNumber.value = '';
                document.salesOrderForm.cellNumber.value = '';
                document.salesOrderForm.faxNumber.value = '';
                document.salesOrderForm.email.value = '';

                document.salesOrderForm.phoneNumber.disabled = true;
                document.salesOrderForm.cellNumber.disabled = true;
                document.salesOrderForm.faxNumber.disabled = true;
                document.salesOrderForm.email.disabled = true;
            }
        }
    }
    var ww = document.salesOrderForm.billingContactPerson.selectedIndex;
    if (element == 'BillingContactPerson')
    {
        for (pp = 0; pp < billContactPerson.length; pp++)
        {
            if (document.salesOrderForm.billingContactPerson.value == billContactPerson[pp])
            {
                document.salesOrderForm.billingContactPerson.value = billContactPerson[pp];

                document.salesOrderForm.billingAddress.value = billAddress[pp].replace(/~/g, '\n');
            }
        }
    }

    if (element == 'ShippingContactPerson')
    {

        for (ff = 0; ff < shipContactPerson.length; ff++)
        {
            if (document.salesOrderForm.shippingContactPerson.value == shipContactPerson[ff])
            {

                document.salesOrderForm.shippingContactPerson.value = shipContactPerson[ff];

                document.salesOrderForm.shippingAddress.value = shipAddress[ff].replace(/~/g, '\n');
            }
        }
    }

}


function selectEndUser()
{
    var endUserId = document.salesOrderForm.endUserId.value;
    if (endUserId != -1)
    {
        enableCustPartNos();//function

        enablePrices();

        document.salesOrderForm.shippingAddress.disabled = false;
        document.salesOrderForm.billingAddress.disabled = false;
        document.salesOrderForm.salesTaxType.disabled = false;
        document.salesOrderForm.miscAsDouble.disabled = false;
        document.salesOrderForm.frieghtAsDouble.disabled = false;
        document.salesOrderForm.action.value = 'loadEndUserDetails';
        document.salesOrderForm.submit();
    }
}
function selectODM()
{
    var odmId = document.salesOrderForm.odmId.value;
    enableCustPartNos();//function
    enablePrices();

    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;
    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;
    document.salesOrderForm.action.value = 'loadODMDetails';
    document.salesOrderForm.submit();
}
function addOptionToSelect(aName, aValue)
{
    var salesPersonObj = document.salesOrderForm.salesPerson;

    addOption(salesPersonObj, aName + "", aValue, salesPersonObj.options.length);

    for (var i = 0; i < salesPersonObj.options.length; i++)
    {
        if (salesPersonObj.options[i].value == document.salesOrderForm.salesPersonName.value)
        {
            salesPersonObj.options[i].selected = true;
        }
    }
}

function addOption(aSelect, aName, aValue, anIndex)
{
    var aOption = new Option(aName, aValue)
    aSelect.options[anIndex] = aOption;
}

function deleteAllOptions()
{

    var salesPersonObj = document.salesOrderForm.salesPerson;
    var optionValue1 = document.salesOrderForm.salesPerson.value;

    if (typeof salesPersonObj != 'undefined')
    {
        for (var j = salesPersonObj.options.length; j >= 0; j--)
        {
            salesPersonObj.options[j] = null;
        }
    }
}
function showHideNewEndUserField()
{
    var form = document.salesOrderForm;
    var endUserCtrl = form.endCustomerId;
    var newEndUserNameCtrl = form.newEndUserName;
    var endUserLabelSpan = document.getElementById("endUserLabelSpan");
    var endUserTxfieldSpan = document.getElementById("endUserTxfieldSpan");
    if (endUserCtrl.value == "-2")
    {
        endUserLabelSpan.style.display = 'block'
        endUserTxfieldSpan.style.display = 'block'
    }
    else
    {
        newEndUserNameCtrl.value = "";
        endUserLabelSpan.style.display = 'none'
        endUserTxfieldSpan.style.display = 'none'
    }
}
function resetForm()
{
    document.salesOrderForm.reset();
    showHideNewEndUserField();
    showHideNewCustPartNo(-1);
}
function showHideNewCustPartNo(selectedIdx)
{
    var form = document.salesOrderForm;
    if (count > 2)
    {
        if (selectedIdx < 0) //All
        {
            for (var k = 0; k < form.customerPartNo.length; k++)
            {
                if (form.customerPartNo[k].value == "-2")
                {
                    form.newCustomerPartNo[k].style.display = "block";
                    form.newCustomerPartNo[k].focus();
                }
                else
                {
                    form.newCustomerPartNo[k].style.display = "none";
                }
            }
        }
        else
        {
            if (form.customerPartNo[selectedIdx].value == "-2")
            {
                form.newCustomerPartNo[selectedIdx].style.display = "block";
                form.newCustomerPartNo[selectedIdx].focus();
            }
            else
            {
                form.newCustomerPartNo[selectedIdx].style.display = "none";
            }
        }
    }
    else
    {
        if (form.customerPartNo.value == "-2")
        {
            form.newCustomerPartNo.style.display = "block";
            form.newCustomerPartNo.focus();
        }
        else
        {
            form.newCustomerPartNo.style.display = "none";
        }
    }
}
function checkValidity(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Contact Person') {
        field_vlaue = document.salesOrderForm.contactPerson.value;
        field_focus = "contactPerson";
    }

    if (field == 'Sales Person') {
        field_vlaue = document.salesOrderForm.salesPerson.value;
        field_focus = "salesPerson";
    }

    if (field == 'Regional Rep') {
        field_vlaue = document.salesOrderForm.regionalRep.value;
        field_focus = "regionalRep";
    }

    if (field == 'End User') {
        field_vlaue = document.salesOrderForm.endUser.value;
        field_focus = "endUser";
    }

    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")"))
        {
            var errMsg = "* " + field + " can not contain #,$,(, and )  Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}
function checkCustomerPONumber(field)
{
    var field_vlaue = document.salesOrderForm.customerPO.value;
    var field_focus = "customerPO";
    var pa = document.getElementById("errors");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if (i == 0 && str == " ")
        {
            var errMsg = "* " + field + " can not start with a space";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "* " + field + " can not contain # $ ( ) . , and &";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkShipping(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Shipping Account') {
        field_vlaue = document.salesOrderForm.shippingAccount.value;
        field_focus = "shippingAccount";
    }

    if (field == 'New Shipping Method') {
        field_vlaue = document.salesOrderForm.newshippingMethod.value;
        field_focus = "newshippingMethod";
    }

    if (field == 'New Shipping Account') {
        field_vlaue = document.salesOrderForm.newshippingAccount.value;
        field_focus = "newshippingAccount";
    }

    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "* " + field + " can not contain # $ ( ) . , and & Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkForDot(field)
{
    var field_vlaue = document.salesOrderForm.shippingTerms.value;
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "."))
        {
            var errMsg = "* " + field + " can not contain . Character";
            pa.innerHTML = errMsg;
            document.salesOrderForm.shippingTerms.focus();
            return false;
        }
    }
}

function checkForBraces(field)
{
    var field_vlaue = document.salesOrderForm.deliveryTerms.value;
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "(") || (str == ")"))
        {


            var errMsg = "* " + field + " can not contain '(' and ')' Characters";
            pa.innerHTML = errMsg;
            document.salesOrderForm.deliveryTerms.focus();
            return false;
        }
    }
}